local sz_shouling = fk.CreateSkill {
  name = "sz_shouling",
  tags = { Skill.Compulsory, },
}


sz_shouling:addEffect(fk.TurnStart, {
  anim_type = "support",
  priority = 3,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(sz_shouling.name) and target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _,pr in ipairs(room.alive_players) do
      if string.startsWith(pr.general,"shanzei") then
        room:addPlayerMark(pr,"@morale")
      end
    end
    local others = room:getOtherPlayers(player,false,true)
    if #others == 0 then return end
    local deadplayer = table.find(others,function(pr) return pr.dead end)
    if deadplayer then
      room:changeHero(deadplayer, "shanzei_loulou", true, false, true)
      room:revivePlayer(deadplayer, false)
      room:askToChooseKingdom({deadplayer})
      -- if deadplayer.role ~= "rebel" then
      --   room:setPlayerProperty(deadplayer, "role", "rebel")
      -- end
      room:drawCards(deadplayer, 4,sz_shouling.name)
    end
  end,
})

sz_shouling:addEffect(fk.DrawNCards, {
  anim_type = "support",
  priority = 3,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@morale") > 2 and target == player
  end,
  on_use = function(self, event, target, player, data)
    data.n = data.n + 1
  end,
})

sz_shouling:addEffect(fk.DamageInflicted, {
  anim_type = "support",
  priority = 3,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@morale") > 3 and not player.dead and data.from and data.from == player and data.card and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
})

sz_shouling:addEffect("maxcards", {
  correct_func = function (self, player)
    if player:getMark("@morale") > 0 then
      return 1
    end
  end,
})

sz_shouling:addEffect("targetmod", {
  residue_func = function(self, player, skill, scope)
    if player:getMark("@morale") > 1 and skill.trueName == "slash_skill" then
      return 1
    end
  end,
})


return sz_shouling